/**
*  \file instrument.c
*
*  \brief
*
*  \author Qilong Huang
*
*
*/
/*===============================================[ private includes  ]================================================*/

#include <stdio.h>
#include <string.h>
#include "instrument.h"
#include "lcd.h"
//#include "menu.h"
//#include "CustomArrayData.h"
//#include "key.h"
//#include "hourmeter.h"
//#include "var_tbl.h"
//#include "icons.h"

/*===============================================[ private defines   ]================================================*/
U8 batt_flash_counter = 0;

/*===============================================[ private datatypes ]================================================*/

/*===============================================[ private variables ]================================================*/
/**
* @brief	Display battary percent and level
* @param	u8	bat_col: the colum of battary.
* @note     none
* @retval   none  
            0%~19%:			    level1
            20%~39%:			level2
            40%~59%:			level3
            60%~79%:			level4
            80%~100%:			level5
*/
void Display_battary_col( U8 bat_col)
{
	U8 i, j, k;
	if(bat_col > 100)
	{
		return;
	}
	else
	{
		i = bat_col / 100;
		j = (bat_col - i * 100) / 10;
		k = bat_col - i * 100 - j * 10;
		if(i == 0)
		{
			LCD_draw_number( 0, 0, SIZE_22, i, HIDE_ENABLE );
		} 
		else
		{
			LCD_draw_number( 0, 0, SIZE_22, i, HIDE_DISABLE );
		}
		if((j == 0) && (i == 0))
		{
			LCD_draw_number(0, 17, SIZE_22, j, HIDE_ENABLE );
		}
		else
		{
			LCD_draw_number(0, 17, SIZE_22, j, HIDE_DISABLE );
		}
		LCD_draw_number(0, 34, SIZE_22, k, HIDE_DISABLE );		
		LCD_draw_sign(0,51,SIZE_22,0);
		if((bat_col >= 80) && (bat_col <= 100))
		{
			LCD_draw_rectangle( 80, 3, 30, 3, Black, HIDE_DISABLE);
			LCD_draw_rectangle( 80, 8, 24, 3, Black, HIDE_DISABLE);
			LCD_draw_rectangle( 80, 13, 15, 3, Black, HIDE_DISABLE);
			LCD_draw_rectangle( 80, 18, 9, 3, Black, HIDE_DISABLE);
			LCD_draw_rectangle( 80, 23, 5, 3, Black, HIDE_DISABLE);
		}
		else if((bat_col >= 60) && (bat_col <= 79))
		{
			LCD_draw_rectangle( 80, 3, 30, 3, White, HIDE_ENABLE);
			LCD_draw_rectangle( 80, 8, 24, 3, Black, HIDE_DISABLE);
			LCD_draw_rectangle( 80, 13, 15, 3, Black, HIDE_DISABLE);
			LCD_draw_rectangle( 80, 18, 9, 3, Black, HIDE_DISABLE);
			LCD_draw_rectangle( 80, 23, 5, 3, Black, HIDE_DISABLE);
		}
		else if((bat_col >= 40) && (bat_col <= 59))
		{
			LCD_draw_rectangle( 80, 3, 30, 3, White, HIDE_ENABLE);
			LCD_draw_rectangle( 80, 8, 24, 3, White, HIDE_ENABLE);
			LCD_draw_rectangle( 80, 13, 15, 3, Black, HIDE_DISABLE);
			LCD_draw_rectangle( 80, 18, 9, 3, Black, HIDE_DISABLE);
			LCD_draw_rectangle( 80, 23, 5, 3, Black, HIDE_DISABLE);
		}
		else if((bat_col >= 20) && (bat_col <= 39))
		{
			LCD_draw_rectangle( 80, 3, 30, 3, White, HIDE_ENABLE);
			LCD_draw_rectangle( 80, 8, 24, 3, White, HIDE_ENABLE);
			LCD_draw_rectangle( 80, 13, 15, 3, White, HIDE_ENABLE);
			LCD_draw_rectangle( 80, 18, 9, 3, Black, HIDE_DISABLE);
			LCD_draw_rectangle( 80, 23, 5, 3, Black, HIDE_DISABLE);
		}
		else
		{
			LCD_draw_rectangle( 80, 3, 30, 3, White, HIDE_ENABLE);
			LCD_draw_rectangle( 80, 8, 24, 3, White, HIDE_ENABLE);
			LCD_draw_rectangle( 80, 13, 15, 3, White, HIDE_ENABLE);
			LCD_draw_rectangle( 80, 18, 9, 3, White, HIDE_ENABLE);
			LCD_draw_rectangle( 80, 23, 5, 3, Black, HIDE_DISABLE);
		}
	}
//    if((BR1189_steer_status.hourmeter_counter_flag == HM_COUNTER_ON) || (BR1189_trac_status.hourmeter_counter_flag == HM_COUNTER_ON) \
//     || (BR1189_lift_status.hourmeter_counter_flag == HM_COUNTER_ON))
    if(BR1189_trac_status.hourmeter_counter_flag == HM_COUNTER_ON)
    {
        Display_hour_counter_sign(HIDE_DISABLE);
    }
    else
    {
        Display_hour_counter_sign(HIDE_ENABLE);
    }

}/*end of Display_battary_col()*/

/**
* @brief	Display Time and Data
            America time is 12 hour, format yy-mm-dd;
            Eurpo time is 24 hour, format dd-mm-yy
* @param	current_time: t_tm time structure
            area: America or Eurpo
* @note     none
* @retval   none  
*/
void Display_data_time(t_tm current_time, u8 area)
{
	U8 year_temp[4], mon_temp[2], date_temp[2], hour_temp[2], min_temp[2], sec_temp[2];
	S8 hour;
	U8 start_col_data = 26;
	U8 start_col_time = 39;
	U8 is_pm = 0x00;
	if(area > 3)
	{
		area = 0;
	}
	year_temp[0] = current_time.t_year / 1000;
	year_temp[1] = (current_time.t_year -  year_temp[0] * 1000) / 100;
	year_temp[2] = (current_time.t_year - year_temp[0] * 1000 - year_temp[1] * 100)  / 10;
	year_temp[3] = current_time.t_year - year_temp[0] * 1000 - year_temp[1] * 100 - year_temp[2] * 10;
	mon_temp[0] = current_time.t_mounth / 10;
	mon_temp[1] = current_time.t_mounth - mon_temp[0] * 10;
	date_temp[0] = current_time.t_date / 10;
	date_temp[1] = current_time.t_date - date_temp[0] * 10;
	hour = current_time.t_hour;
	min_temp[0] = current_time.t_min / 10;
	min_temp[1] = current_time.t_min - min_temp[0] * 10;
	sec_temp[0] = current_time.t_sec / 10;
	sec_temp[1] = current_time.t_sec - sec_temp[0] * 10;
	if(area == China)
	{
		hour_temp[0] = hour / 10;
		hour_temp[1] = hour - hour_temp[0] * 10;
		LCD_draw_number(4, start_col_data, SIZE_10, year_temp[2], HIDE_DISABLE );
		LCD_draw_number(4, start_col_data + 8, SIZE_10, year_temp[3], HIDE_DISABLE );
		LCD_draw_sign(4, start_col_data + 16, SIZE_10, 1 );
		LCD_draw_number(4, start_col_data + 24, SIZE_10, mon_temp[0], HIDE_DISABLE );
		LCD_draw_number(4, start_col_data + 32, SIZE_10, mon_temp[1], HIDE_DISABLE );
	    LCD_draw_sign(4, start_col_data + 40, SIZE_10, 1 );
		LCD_draw_number(4, start_col_data + 48, SIZE_10, date_temp[0], HIDE_DISABLE );
		LCD_draw_number(4, start_col_data + 56, SIZE_10, date_temp[1], HIDE_DISABLE );

		LCD_draw_number(6, start_col_time, SIZE_10, hour_temp[0], HIDE_DISABLE );
		LCD_draw_number(6, start_col_time + 8, SIZE_10, hour_temp[1], HIDE_DISABLE );
		if((current_time.t_sec % 2) == 1)
		{
		    LCD_draw_sign(6, start_col_time + 16, SIZE_10, 2 );
		}
		else
		{
		    LCD_draw_sign(6, start_col_time + 16, SIZE_10, 8 );
		}		
		LCD_draw_number(6, start_col_time + 24, SIZE_10, min_temp[0], HIDE_DISABLE );
		LCD_draw_number(6, start_col_time + 32, SIZE_10, min_temp[1], HIDE_DISABLE );	
	}
	else if(area == America)
	{
		if(hour > 12) 
		{
			hour -= 12;
			is_pm = 0x01;
		}
		hour_temp[0] = hour / 10;
		hour_temp[1] = hour - hour_temp[0] * 10;
		start_col_time -= 14;
		LCD_draw_number(4, start_col_data, SIZE_10, year_temp[2], HIDE_DISABLE );
		LCD_draw_number(4, start_col_data + 8, SIZE_10, year_temp[3], HIDE_DISABLE );
		LCD_draw_sign(4, start_col_data + 16, SIZE_10, 1 );
		LCD_draw_number(4, start_col_data + 24, SIZE_10, mon_temp[0], HIDE_DISABLE );
		LCD_draw_number(4, start_col_data + 32, SIZE_10, mon_temp[1], HIDE_DISABLE );
	    LCD_draw_sign(4, start_col_data + 40, SIZE_10, 1 );
		LCD_draw_number(4, start_col_data + 48, SIZE_10, date_temp[0], HIDE_DISABLE );
		LCD_draw_number(4, start_col_data + 56, SIZE_10, date_temp[1], HIDE_DISABLE );
		
		LCD_draw_number(6, start_col_time, SIZE_10, hour_temp[0], HIDE_DISABLE );
		LCD_draw_number(6, start_col_time + 8, SIZE_10, hour_temp[1], HIDE_DISABLE );
		if((current_time.t_sec % 2) == 1)
		{
		    LCD_draw_sign(6, start_col_time + 16, SIZE_10, 2 );
		}
		else
		{
		    LCD_draw_sign(6, start_col_time + 16, SIZE_10, 8 );
		}
		LCD_draw_number(6, start_col_time + 24, SIZE_10, min_temp[0], HIDE_DISABLE );
		LCD_draw_number(6, start_col_time + 32, SIZE_10, min_temp[1], HIDE_DISABLE );

		//LCD_draw_number(6, start_col_time + 40, SIZE_10, sec_temp[0], HIDE_DISABLE );
		//LCD_draw_number(6, start_col_time + 48, SIZE_10, sec_temp[1], HIDE_DISABLE );
		if(is_pm == 0x01 )
		{
		    put_string(6,start_col_time + 40,SIZE_10," PM", HIDE_DISABLE);
		}
		else
		{
		    put_string(6,start_col_time + 40,SIZE_10," AM", HIDE_DISABLE);
		}
	}
	else if(area == Eurpo)
	{
		hour_temp[0] = hour / 10;
		hour_temp[1] = hour - hour_temp[0] * 10;
		
		LCD_draw_number(4, start_col_data, SIZE_10, date_temp[0], HIDE_DISABLE );
		LCD_draw_number(4, start_col_data + 8, SIZE_10, date_temp[1], HIDE_DISABLE );
		LCD_draw_sign(4, start_col_data + 16, SIZE_10, 1 );
		LCD_draw_number(4, start_col_data + 24, SIZE_10, mon_temp[0], HIDE_DISABLE );
		LCD_draw_number(4, start_col_data + 32, SIZE_10, mon_temp[1], HIDE_DISABLE );
		LCD_draw_sign(4, start_col_data + 40, SIZE_10, 1 );
		LCD_draw_number(4, start_col_data + 48, SIZE_10, year_temp[2], HIDE_DISABLE );
		LCD_draw_number(4, start_col_data + 56, SIZE_10, year_temp[3], HIDE_DISABLE );
		
		LCD_draw_number(6, start_col_time, SIZE_10, hour_temp[0], HIDE_DISABLE );
		LCD_draw_number(6, start_col_time + 8, SIZE_10, hour_temp[1], HIDE_DISABLE );
		if((current_time.t_sec % 2) == 1)
		{
		    LCD_draw_sign(6, start_col_time + 16, SIZE_10, 2 );
		}
		else
		{
		    LCD_draw_sign(6, start_col_time + 16, SIZE_10, 8 );
		}		
		LCD_draw_number(6, start_col_time + 24, SIZE_10, min_temp[0], HIDE_DISABLE );
		LCD_draw_number(6, start_col_time + 32, SIZE_10, min_temp[1], HIDE_DISABLE );	
	}
}/*end of Display_data_time()*/

/**
* @brief	Display hour counter sign
            If hour meter enable, the sign will show on the fixed area
* @param	is_hide: HIDE_ENABLE---hide, HIDE_DISABLE---show
* @note     none
* @retval   none  
*/
void Display_hour_counter_sign(U8 is_hide)
{
    u8 i, j;
	if(is_hide == HIDE_DISABLE)
	{
//		LCD_draw_rectangle( 102, 17, 9, 9, White, HIDE_DISABLE );
//		LCD_draw_line( 102, 17,  110, 25 );
//		LCD_draw_line( 110, 17,  102, 25 );
        for(i = 0; i < 2; i ++)
        {
            for(j = 0; j < 8; j ++)
            {
                OLED_GRAM[2 + i][102 + j] = time_log[i * 8 + j];
            }
        }
    }
	else if(is_hide == HIDE_ENABLE)
	{
		LCD_ersea_area( 102, 16, 8, 16 );
	}
}/*end of Display_hour_counter_sign()*/

/**
* @brief	Display the scrollbar's status on the right side of LCD
* @param	status: 0~15, 0: scrollbar hide
* @note     none
* @retval   none  
*/
void Display_scrollbar(U8 status)
{
	switch(status)
	{
		case 0:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_ENABLE, HIDE_ENABLE, HIDE_ENABLE );break;
		case 1:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_ENABLE, HIDE_ENABLE, HIDE_DISABLE );break;
		case 2:	 LCD_draw_scrollbar( HIDE_ENABLE, HIDE_ENABLE, HIDE_DISABLE, HIDE_ENABLE );break;
		case 3:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_ENABLE, HIDE_DISABLE, HIDE_DISABLE );break;
		case 4:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_DISABLE, HIDE_ENABLE, HIDE_ENABLE );break;
		case 5:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_DISABLE, HIDE_ENABLE, HIDE_DISABLE );break;
		case 6:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_DISABLE, HIDE_DISABLE, HIDE_ENABLE );break;
		case 7:  LCD_draw_scrollbar( HIDE_ENABLE, HIDE_DISABLE, HIDE_DISABLE, HIDE_DISABLE );break;
		case 8:  LCD_draw_scrollbar( HIDE_DISABLE, HIDE_ENABLE, HIDE_ENABLE, HIDE_ENABLE );break;
		case 9:  LCD_draw_scrollbar( HIDE_DISABLE, HIDE_ENABLE, HIDE_ENABLE, HIDE_DISABLE );break;
		case 10: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_ENABLE, HIDE_DISABLE, HIDE_ENABLE );break;	 
		case 11: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_ENABLE, HIDE_DISABLE, HIDE_DISABLE );break;
		case 12: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_DISABLE, HIDE_ENABLE, HIDE_ENABLE );break;
		case 13: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_DISABLE, HIDE_ENABLE, HIDE_DISABLE );break;
		case 14: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_DISABLE, HIDE_DISABLE, HIDE_ENABLE );break;
		case 15: LCD_draw_scrollbar( HIDE_DISABLE, HIDE_DISABLE, HIDE_DISABLE, HIDE_DISABLE );break;
		default: break;
	}
}/*end of Display_scrollbar()*/

/**
* @brief	Display the hour meter on the fixed location of LCD
* @param	hour_counter: hour meter time
            is_hide: hide or show
* @note     none
* @retval   none  
*/
void Display_hour_meter(S32 hour_counter, U8 is_hide)
{
	U8 hour_counter_temp[6];
	U8 Start_x = 13;
	U8 Start_y = 5;
	U8 i, j, zero_num = 0;
	U8 k;
	if((hour_counter < 0) || (hour_counter > 999999))
	{
		return;
	}
	if(is_hide == HIDE_DISABLE)
	{
		//Clear the hour meter areas
		for(i = 0; i < 2; i ++)
		{
			for(j = 0; j < 118; j++)
			{
				OLED_GRAM[i + Start_y][j + Start_x] = 0x00;
			}
		}	
		hour_counter_temp[0] = hour_counter / 100000;
		hour_counter_temp[1] = (hour_counter - hour_counter_temp[0] * 100000) / 10000;
		hour_counter_temp[2] = (hour_counter - hour_counter_temp[0] * 100000 - hour_counter_temp[1] * 10000) / 1000;
		hour_counter_temp[3] = (hour_counter - hour_counter_temp[0] * 100000 - hour_counter_temp[1] * 10000 - hour_counter_temp[2] * 1000) / 100;
		hour_counter_temp[4] = (hour_counter - hour_counter_temp[0] * 100000 - hour_counter_temp[1] * 10000 - hour_counter_temp[2] * 1000 - hour_counter_temp[3] * 100) / 10;
		hour_counter_temp[5] = hour_counter - hour_counter_temp[0] * 100000 - hour_counter_temp[1] * 10000 - hour_counter_temp[2] * 1000 - hour_counter_temp[3] * 100 - hour_counter_temp[4] * 10;
		
		//Search how much 0 ahead of the hourcounter
		for(k = 0; k < 6; k ++)
		{
			if(hour_counter_temp[k] == 0)
			{
				zero_num ++;
			}
			else
			{
				break;
			}
		}
		//if all the hour_counter_temp are 0, then display a '0h'
		if(zero_num == 6)
		{
			zero_num = 5;
		}
		// calculate the start x column
		Start_x = (118 - (6 - zero_num) * 13) / 2;
		for(k = zero_num; k < 6; k ++)
		{
			LCD_draw_number(Start_y, Start_x + 13 * (k - zero_num), SIZE_12, hour_counter_temp[k], HIDE_DISABLE );
		}
		for(i = 0; i < 2; i ++)
		{
			for(j = 0; j < 13; j++)
			{
				OLED_GRAM[i + Start_y][j + Start_x + 13 * (k - zero_num)] = char_h_lower_Size12[i * 13 + j];
			}
		}		
	}
	else
	{
		for(i = 0; i < 2; i ++)
		{
			for(j = 0; j < 118; j++)
			{
				OLED_GRAM[i + Start_y][j + Start_x] = 0x00;
			}
		}	
	}
}/*end of display_hour_meter()*/

/**
* @brief	Display adjust bar on the lcd to adjust the brightness and the contrast
* @param	bar_kind: Choose the display bar kind.
                      CONTRAST_BAR: Adjust the contrast
                      LIGHTING_BAR: Adjust the loghting
            value: Adjust value from 0~7
            is_hide: hide or show
* @note     none
* @retval   none  
*/
void Display_adjust_bar( U8 bar_kind, S16 value , U8 is_hide)
{
	U8 Start_x = 3;
	U8 Start_y = 40;
	U8 i;
//	if((value < 0) || (value > 6))
//	{
//		return;
//	}
    if(value < 0)
    {
        value = 0;
    }
    else if(value > 6)
    {
        value = 6;
    }
	if(is_hide == HIDE_DISABLE)
	{
		LCD_draw_rectangle( Start_x, Start_y, 3, 16, White, HIDE_DISABLE);
		if(bar_kind == CONTRAST_BAR)
		{           
			put_string(5, Start_x + 15, SIZE_7, "CONTRAST", HIDE_DISABLE);
		}
		else if(bar_kind == LIGHTING_BAR)
		{
            if(Language == LANGUAGE_EN )
            {
			    put_string(5, Start_x + 15, SIZE_7, "Lighting", HIDE_DISABLE);
            }
            else if(Language == LANGUAGE_CH )
            {
                Display_Light_ch_pic();
            }
		}
		
		LCD_draw_rectangle( Start_x + 64 , Start_y, 3, 16, Black, HIDE_DISABLE);
		for(i = 0; i < 9; i ++)
		{
			LCD_draw_rectangle( Start_x + i * 8 , 59, 3, 3, White, HIDE_DISABLE);
		}
		//Clear the bar area
		for(i = Start_x + 8; i < Start_x + 59; i ++)
		{
			OLED_GRAM[6][i] = 0x00;
		}	
		LCD_draw_rectangle( Start_x + ((value + 1) * 8) , 53, 3, 3, Black, HIDE_DISABLE); 
	}
}/*end of Display_adjust_bar()*/
/**
* @brief	Display welcome picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_welcome_pic(void)
{
	u8 i, j;
	for(i = 0; i < 8; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            if(Language == LANGUAGE_EN)
            {
                OLED_GRAM[i][j] = welcome_pic[i][j];
            }
            else if(Language == LANGUAGE_CH)
            {
                OLED_GRAM[i][j] = welcome_pic_cn[i][j];
            }
		}
	}
}// end Display_welcome_pic() 

/**
* @brief	Display pin code chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_pincode_ch_pic(void)
{
	u8 i, j;
	for(i = 0; i < 3; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 1][j] = input_pincode_cn[i * 128 + j];
		}
	}
}// end Display_pincode_ch_pic() 
/**
* @brief	Display pin code chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_Light_ch_pic(void)
{
	u8 i, j;
	for(i = 0; i < 2; i ++)
	{
		for(j = 0; j < 44; j ++)
		{
            OLED_GRAM[i + 4][j + 15] = back_light_cn[i * 44 + j];
		}
	}
}// end Display_pincode_ch_pic()
/**
* @brief	Display next service time chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_next_service_ch_pic(void)
{
	u8 i, j;
	for(i = 0; i < 2; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 5][j] = next_service_time_cn[i * 128 + j];
		}
	}
}// end void Display_next_service_ch_pic(void)
/**
* @brief	Display  tempurature too high chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_MotoTemp_tooHigh1_ch(void)
{
	u8 i, j;
	for(i = 0; i < 2; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 4][j] = moto_tempurature_too_high1_cn[i * 128 + j];
		}
	}
}// end void Display_MotoTemp_tooHigh1_ch(void)

/**
* @brief	Display oil lack chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_OilLack_ch(void)
{
	u8 i, j;
	for(i = 0; i < 4; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 4][j] = oil_lack_cn[i * 128 + j];
		}
	}
}// end void Display_OilLack_ch(void)
/**
* @brief	Display oil lack chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_Maintance_ch(void)
{
	u8 i, j;
	for(i = 0; i < 4; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 4][j] = maintance_info_cn[i * 128 + j];
		}
	}
}// end void Display_OilLack_ch(void)
/**
* @brief	Display battery cut off chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_BatteryCutOff_ch(void)
{
	u8 i, j;
	for(i = 0; i < 4; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 4][j] = bat_cutoff_info_cn[i * 128 + j];
		}
	}
}// end void Display_BatteryCutOff_ch(void)
/**
* @brief	Display battery low chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_Batlow_ch(void)
{
	u8 i, j;
	batt_flash_counter ++;
	if(batt_flash_counter >= 6)
	{
		batt_flash_counter = 0;
	}
	for(i = 0; i < 4; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
			if(batt_flash_counter <= 2)
			{
				OLED_GRAM[i + 4][j] = bat_low_info_cn[0][i * 128 + j];
			}
            else
			{
				OLED_GRAM[i + 4][j] = bat_low_info_cn[1][i * 128 + j];
			}
			
		}
	}	
}
/**
* @brief	Display tempurature too high chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_MotoTemp_tooHigh2_ch(void)
{
	u8 i, j;
	for(i = 0; i < 4; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 4][j] = moto_tempurature_too_high2_cn[i * 128 + j];
		}
	}
}// end void Display_MotoTemp_tooHigh2_ch(void)

/**
* @brief	Display pin code chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_Confirm_Delete_ch(void)
{
	u8 i, j;
	for(i = 0; i < 4; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 4][j] = delete_confirm_cn[i * 128 + j];
		}
	}
}// end void Display_OilLack_ch(void)
/**
* @brief	put string on the lcd
* @param	start_row: Start page, from 0 ~ 7
            start_column: Start column, from 0 ~ 127
            *string: The string you want to display
            is_hide: hide or show
* @note     none
* @retval   none  
*/
void put_string(S16 start_row, S16 start_column, font_size size, char *string, U8 is_hide)
{
	char character;
	char number;
	if(is_hide == HIDE_DISABLE)
	{
		do
		{
			character = *string;
			if((character >= 65) && (character <= 90))
			{
				LCD_draw_upperchar(start_row, start_column, size, character, HIDE_DISABLE);
				
			}
			else if((character >= 48) && (character <= 57))
			{
				number = character - 48;
				LCD_draw_number(start_row, start_column, size, number, HIDE_DISABLE);
			}
			else if((character >= 97) && (character <= 122))
			{
				LCD_draw_lowerchar(start_row, start_column, size, character, HIDE_DISABLE);			
			}
			else
			{
				switch (character)
				{
					case '%': LCD_draw_sign( start_row, start_column, size, 0); break;	//Display '%'
					case '/': LCD_draw_sign( start_row, start_column, size, 1); break;	//Display '/'
					case ':': LCD_draw_sign( start_row, start_column, size, 2); break;	//Display ':'
					case '!': LCD_draw_sign( start_row, start_column, size, 3); break;	//Display '!'
					case '+': LCD_draw_sign( start_row, start_column, size, 4); break;	//Display '+'
					case '-': LCD_draw_sign( start_row, start_column, size, 5); break;	//Display '-'
					case ';': LCD_draw_sign( start_row, start_column, size, 6); break;	//Display ';'
					case '.': LCD_draw_sign( start_row, start_column, size, 7); break;	//Display '.'
					case ' ': LCD_draw_sign( start_row, start_column, size, 8); break;	//Display ' '
					case '*': LCD_draw_sign( start_row, start_column, size, 9); break;	//Display ' '
                    case '?': LCD_draw_sign( start_row, start_column, size, 10); break;	//Display ' '
					default: break;
				}
			}		
            if(size == SIZE_7)
			{
			    // To adjust the distence between to near characters
				if((character == 'I') || (character == 'i') || (character == 'l') || (character == '!') || (character == '.') )
			    {
				    start_column += 2;
			    }
			    else if((character == 'j') || (character == ':') || (character == ';')\
					|| (character == ' ') )
			    {
				    start_column += 3;
			    }
				else if((character == 'E') || (character == 'F')|| (character == 'J')|| (character == 'L')\
				    || (character == 'f') || (character == 's') || (character == 't') || (character == '1'))
			    {
				    start_column += 4;
			    }
				else if((character == 'Z') || (character == '4'))
			    {
				    start_column += 7;
			    }
				else if((character == 'M') || (character == 'W') || (character == 'w') || (character == '*'))
			    {
				    start_column += 8;
			    }
                else if(character == '%')
			    {
				    start_column += 9;
			    }
			    else
			    {
				    start_column += 6;
			    }
			}
			else if(size == SIZE_10)
			{
				if((character == 'I') || (character == 'l'))
				{
					start_column += 3;
				}
				else if((character == 'J') || (character == 'i')|| (character == ':')|| (character == '!')|| (character == ';')|| (character == '.')|| (character == ' '))
				{
					start_column += 4;
				}
				else if((character == '4') || (character == 'E') || (character == 'F') ||(character == 'L') \
					|| (character == 'f')|| (character == 'j')||(character == 'r')||(character == 's')||(character == 't'))
				{
				    start_column += 6;
				}
				else if((character == 'C') || (character == 'P') ||(character == 'S') || (character == 'T')\
					|| (character == 'Z')||(character == 'a')||(character == 'c')||(character == 'e') ||(character == 'k')\
				    || (character == '0')||(character == '2')||(character == '3')||(character == '4') ||(character == '5')\
				    || (character == '6')||(character == '7')||(character == '8')||(character == '9'))
				{
				    start_column += 7;
				}
				else if((character == 'A') || (character == 'V') ||(character == 'X') || (character == 'v')\
					|| (character == 'x')||(character == 'y')||(character == '+'))
				{
				    start_column += 9;
				}
				else if(character == 'M')
				{
				    start_column += 10;
				}
				else if((character == '*')||(character == '-'))
				{
				    start_column += 11;
				}
				else if((character == 'W')|| (character == 'm') ||(character == 'w'))
				{
				    start_column += 12;
				}
				else if(character == '%')
				{
				    start_column += 13;
				}
				else
				{
				    start_column += 8;
				}
			}
			
			string ++;
		}
		while(character != '\0');
	}
}/*end of put_string()*/

void show_hourmeter_number(S16 start_row, U32 hourmeter_10times)
{
	u8 temp_data[6], i, zero_bit_num = 0, start_column;
    if(hourmeter_10times > 100000)
        return;
    temp_data[0] = hourmeter_10times / 100000;
    temp_data[1] = (hourmeter_10times - temp_data[0] * 100000) / 10000;
    temp_data[2] = (hourmeter_10times - temp_data[0] * 100000 - temp_data[1] * 10000) / 1000;
    temp_data[3] = (hourmeter_10times - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000) / 100;
    temp_data[4] = (hourmeter_10times - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000 - temp_data[3] * 100 ) / 10;
    temp_data[5] = hourmeter_10times - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000 - temp_data[3] * 100 - temp_data[4] * 10;
    for(i = 0; i < 4; i ++)
    {
        if(temp_data[i] == 0)
        {
            zero_bit_num ++;
        }
        else
        {
             break;
        }     
    }
    start_column = 64 - (((4 - zero_bit_num) * 6 + 23) / 2);                 // find the adapt location of x pos
    for(i = zero_bit_num; i < 4; i ++)
    {
        LCD_draw_number(start_row, start_column, SIZE_7, temp_data[i], HIDE_DISABLE);
        start_column += 6;
    }
    LCD_draw_number(start_row, start_column, SIZE_7, temp_data[4], HIDE_DISABLE);
    start_column += 6;
    LCD_draw_sign( start_row, start_column, SIZE_7, 7);                        // '.'
    start_column += 2;
    LCD_draw_number(start_row, start_column, SIZE_7, temp_data[5], HIDE_DISABLE);
    start_column += 6;
    LCD_draw_sign( start_row, start_column, SIZE_7, 8);                        // ' ' 
    start_column += 3;
    LCD_draw_lowerchar(start_row, start_column, SIZE_7, 'h', HIDE_DISABLE);	
}/*end of show_hourmeter_number()*/

void show_service_hour(S16 start_row, U32 service_hour)
{
	u8 temp_data[6], i, zero_bit_num = 0, start_column;
    if(service_hour > 100000)
        return;
    temp_data[0] = service_hour / 100000;
    temp_data[1] = (service_hour - temp_data[0] * 100000) / 10000;
    temp_data[2] = (service_hour - temp_data[0] * 100000 - temp_data[1] * 10000) / 1000;
    temp_data[3] = (service_hour - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000) / 100;
    temp_data[4] = (service_hour - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000 - temp_data[3] * 100 ) / 10;
    temp_data[5] = service_hour - temp_data[0] * 100000 - temp_data[1] * 10000 - temp_data[2] * 1000 - temp_data[3] * 100 - temp_data[4] * 10;
    for(i = 0; i < 5; i ++)
    {
        if(temp_data[i] == 0)
        {
            zero_bit_num ++;
        }
        else
        {
             break;
        }     
    }
    start_column = 64 - (((5 - zero_bit_num) * 6 + 23) / 2);                 // find the adapt location of x pos
    for(i = zero_bit_num; i < 5; i ++)
    {
        LCD_draw_number(start_row, start_column, SIZE_7, temp_data[i], HIDE_DISABLE);
        start_column += 6;
    }
    LCD_draw_number(start_row, start_column, SIZE_7, temp_data[5], HIDE_DISABLE);
    start_column += 6;
    LCD_draw_sign( start_row, start_column, SIZE_7, 8);                        // ' ' 
    start_column += 3;
    LCD_draw_lowerchar(start_row, start_column, SIZE_7, 'h', HIDE_DISABLE);	
}/*end of show_hourmeter_number()*/

/**
* @brief	Display pin code chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_admin_pincode_ch_pic(void)
{
	u8 i, j;
	for(i = 0; i < 3; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 1][j] = input_adminpincode_cn[i * 128 + j];
		}
	}
}// end Display_pincode_ch_pic() 

void Display_enter_pincode_ch_pic(void)
{
	u8 i, j;
	for(i = 0; i < 3; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 1][j] = input_enternewpincode_cn[i * 128 + j];
		}
	}
}

/**
* @brief	Display add pin code confirm chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_Confirm_AddPincode_ch(void)
{
	u8 i, j;
	for(i = 0; i < 4; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i + 4][j] = add_pincode_confirm_cn[i * 128 + j];
		}
	}
}// end void Display_Confirm_AddPincode_ch(void)

/**
* @brief	Display add pin code chinese picture on the lcd
* @param	none
* @note     none
* @retval   none
*/
void Display_NewPincode_ch(void)
{
	u8 i, j;
	for(i = 0; i < 2; i ++)
	{
		for(j = 0; j < 128; j ++)
		{
            OLED_GRAM[i][j] = new_pincode_cn[i * 128 + j];
		}
	}
}// end void Display_OilLack_ch(void)
/***********************************************************************************************************************
*                             Copyright 2016 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/


